const scraperMixin = {
  data() {
    return {
      option: {
        height: 'calc(100vh - 440px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        // searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        addBtn: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        selection: true,
        menuWidth: 300, //弹框内字段宽度属性
        dialogWidth: 880, //弹框宽度属性
        labelWidth: '110',
        dialogClickModal: false,
        columnBtn: false,
        searchMenuPosition: 'right',
        column: [
          {
            label: '编码',
            prop: 'code',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入编码'
              }
            ]
          },
          {
            label: '名称',
            prop: 'name',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入名称'
              }
            ]
          },
          {
            label: '规格',
            prop: 'specification',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入规格'
              }
            ]
          },
          {
            label: '新增时间',
            prop: 'createTime'
          },
          {
            label: '版本',
            prop: 'version'
          },
          {
            label: '型号',
            prop: 'model'
          },
          {
            label: '批次',
            prop: 'lotNo'
          },
          {
            label: '状态',
            prop: 'status',
            search: true,
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=steel_mesh_status',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '最大使用次数',
            prop: 'maxUsage'
          },
          {
            label: '已使用次数',
            prop: 'timesUsed'
          },
          {
            label: '剩余可用次数',
            prop: 'remainingUsedTimes'
            // formatter: (val, value, label) => {
            //     if (!val.maxUsage || val.maxUsage == null) {
            //         return 0;
            //     } else if (val.timesUsed && Number(val.maxUsage) < Number(val.timesUsed)) {
            //         return 0;
            //     } else if (val.maxUsage && Number(val.maxUsage) >= Number(val.timesUsed)) {
            //         return val.maxUsage - val.timesUsed;
            //     } else {
            //         return value;
            //     }
            // }
          }
        ]
      },
      dialogOption: {
        emptyBtn: false,
        submitBtn: false,
        detail: false,
        labelWidth: 160,
        group: [
          {
            label: '基本数据',
            arrow: false,
            prop: 'baseInfo',
            labelWidth: 100,
            display: true,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '编码',
                prop: 'code',
                search: true,
                span: 8,
                rules: [
                  {
                    required: true,
                    message: '请输入编码'
                  }
                ]
              },
              {
                label: '名称',
                prop: 'name',
                search: true,
                span: 8,
                rules: [
                  {
                    required: true,
                    message: '请输入名称'
                  }
                ]
              },
              {
                label: '规格',
                prop: 'specification',
                span: 8,
                rules: [
                  {
                    required: true,
                    message: '请输入规格'
                  }
                ]
              },
              {
                label: '版本',
                prop: 'version',
                span: 8
              },
              {
                label: '型号',
                prop: 'model',
                span: 8
              },
              {
                label: '批次',
                prop: 'lotNo',
                span: 8
              },
              {
                label: '环保类型',
                prop: 'epType',
                type: 'select',
                dicUrl: '/api/blade-system/dict/dictionary?code=equipment_ep_type',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                span: 8
              },
              {
                label: '厚度',
                prop: 'thickness',
                span: 8
              },
              {
                label: '倾斜角',
                prop: 'slantAngle',
                span: 8
              },
              {
                label: '负责部门',
                prop: 'principalDeptId',
                type: 'tree',
                dicUrl: '/api/blade-system/dept/tree',
                props: {
                  label: 'title',
                  value: 'id'
                },
                checkStrictly: true,
                defaultExpandAll: true,
                slot: true,
                span: 8
              },
              {
                label: '负责人员',
                prop: 'principalName',
                type: 'search',
                disabled: true,
                span: 8,
                appendClick: () => {
                  this.openUserCommonModal();
                }
              },
              {
                label: '存储位置',
                prop: 'areaName',
                span: 8,
                type: 'search',
                disabled: true,
                appendClick: () => {
                  this.openAreaCommonModal();
                }
              },
              {
                label: '备注',
                prop: 'remark',
                type: 'textarea',
                minRows: 3,
                maxRows: 3,
                span: 8
              }
            ]
          },
          {
            label: '使用信息',
            arrow: false,
            prop: 'useInfo',
            labelWidth: 110,
            display: true,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '最大使用次数',
                prop: 'maxUsage',
                span: 8,
                type: 'number',
                controls: false,
                rules: [
                  {
                    required: true,
                    message: '请输入最大使用次数'
                  },
                  {
                    required: false,
                    trigger: 'blur',
                    validator: (rule, value, callback) => {
                      let reg = /^\+?[0-9]\d*$/;
                      if (!reg.test(value)) {
                        callback(new Error('请输入整数'));
                      } else {
                        callback();
                      }
                    }
                  }
                ]
              },
              {
                label: '已使用次数',
                prop: 'timesUsed',
                disabled: true,
                span: 8
              },
              {
                label: '剩余使用次数',
                prop: 'remainingUsedTimes',
                disabled: true,
                span: 8
              }
            ]
          },
          {
            label: '购置信息',
            arrow: false,
            prop: 'purchaseInfo',
            labelWidth: 100,
            display: true,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '资产编码',
                prop: 'assetCode',
                span: 8
              },
              {
                label: '购置价格',
                prop: 'procurementPrice',
                span: 8
              },
              {
                label: '供应商',
                prop: 'vendorName',
                span: 8,
                type: 'search',
                disabled: true,
                appendClick: () => {
                  this.openVendorCommonModal();
                }
              },
              {
                label: '购置日期',
                prop: 'procurementDate',
                span: 8,
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm:ss',
                valueFormat: 'yyyy-MM-dd HH:mm:ss'
              },
              {
                label: '入账日期',
                prop: 'acceptanceDate',
                span: 8,
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm:ss',
                valueFormat: 'yyyy-MM-dd HH:mm:ss'
              },
              {
                label: '出厂日期',
                prop: 'manufactureDate',
                span: 8,
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm:ss',
                valueFormat: 'yyyy-MM-dd HH:mm:ss'
              },
              {
                label: '启用日期',
                prop: 'commissioningDate',
                span: 8,
                type: 'datetime',
                format: 'yyyy-MM-dd HH:mm:ss',
                valueFormat: 'yyyy-MM-dd HH:mm:ss'
              }
            ]
          },
          {
            label: '附件信息',
            arrow: false,
            prop: 'attachInfo',
            labelWidth: 110,
            display: true,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '设备图片',
                prop: 'PICTURE',
                type: 'upload',
                span: 8
              },
              {
                label: '验收报告附件',
                prop: 'INSPECTION',
                type: 'upload',
                span: 8
              },
              {
                label: '投产验证附件',
                prop: 'CERT',
                type: 'upload',
                span: 8
              }
            ]
          }
        ]
      },
      detailOption: {
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuPosition: 'right',
        height: '400px',
        searchLabelWidth: 100,
        dialogClickModal: false,
        border: true,
        columnBtn: false,
        viewBtn: false,
        addBtn: false,
        selection: false,
        printBtn: false,
        editBtn: false,
        delBtn: false,
        index: false,
        menu: false,
        refreshBtn: false,
        // viewText: '详情',
        menuWidth: 100,
        column: []
      },
      usedRecordColumn: [
        {
          label: '编码',
          prop: 'toolCode',
          searchSpan: 6
        },
        {
          label: '工单号',
          prop: 'workOrderNo',
          searchSpan: 6
        },
        {
          label: '产品编码',
          prop: 'partNo'
        },
        {
          label: '设备编码',
          prop: 'equipmentCode'
        },
        {
          label: '领用时间',
          prop: 'requestDate'
        },
        {
          label: '领用人',
          prop: 'requestByName',
          searchSpan: 6
        },
        {
          label: '上机时间',
          prop: 'onlineDate'
        },
        {
          label: '上机人',
          prop: 'onlineByName'
        },
        {
          label: '归还时间',
          prop: 'returnDate'
        },
        {
          label: '归还人',
          prop: 'returnByName'
        },
        {
          label: '本次使用次数',
          prop: 'timesUsedThis',
          width: 120
        }
      ],
      inspectionColumn: [
        {
          label: '编码',
          prop: 'equipmentCode'
        },
        {
          label: '检验结果',
          prop: 'examineResult',
          dicData: [
            {
              label: '合格',
              value: 'OK'
            },
            {
              label: '不合格',
              value: 'NG'
            }
          ]
        },
        {
          label: '检验人',
          prop: 'examineByName'
        },
        {
          label: '检验日期',
          prop: 'examineDate'
        },
        {
          label: '备注',
          prop: 'remark',
          span: 10,
          minRows: 3,
          maxRows: 3
        }
      ],
      inspectionDetailOption: {
        emptyBtn: false,
        submitBtn: false,
        detail: true,
        labelWidth: 160,
        group: [
          {
            label: '基本数据',
            arrow: false,
            prop: 'baseInfo',
            labelWidth: 100,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '编码',
                prop: 'equipmentCode'
              },
              {
                label: '名称',
                prop: 'equipmentName'
              },
              {
                label: '规格',
                prop: 'specification'
              },
              {
                label: '厚度',
                prop: 'thickness',
                span: 8
              },
              {
                label: '倾斜角',
                prop: 'slantAngle',
                span: 8
              },
              {
                label: '存储位置',
                prop: 'areaName',
                span: 8
              }
            ]
          },
          {
            label: '检验记录',
            arrow: false,
            prop: 'inspectionInfo',
            labelWidth: 100,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '检验结果',
                prop: 'examineResult',
                type: 'radio',
                row: true,
                dicData: [
                  {
                    label: '合格',
                    value: 'OK'
                  },
                  {
                    label: '不合格',
                    value: 'NG'
                  }
                ]
              },
              {
                label: '检验照片',
                prop: 'picture'
              },
              {
                label: '检验附件',
                prop: 'attach',
                row: true
              },
              {
                label: '检验人',
                prop: 'examineByName',
                row: true
              },
              {
                label: '检验时间',
                prop: 'examineDate',
                row: true
              },
              {
                label: '备注',
                prop: 'remark',
                type: 'textarea',
                row: true,
                minRows: 3,
                maxRows: 3
              }
            ]
          }
        ]
      }
    };
  },
  methods: {
    /**
     * 打开地址选择模态框
     */
    openAreaCommonModal() {
      this.modalName = 'areaModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择存储位置（双击进行选择）',
        url: '/api/mes-admin/area/page/storage/management',
        isPage: true,
        lazy: true,
        index: false,
        query: {
          parentId: 0
        },
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '名称',
            prop: 'name',
            labelWidth: 150,
            search: true,
            order: 1
          },
          {
            label: '编码',
            prop: 'code',
            labelWidth: 150,
            search: true,
            order: 2
          },
          {
            label: '仓库类型',
            prop: 'inventoryType',
            type: 'select',
            order: 3,
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            dicUrl: '/api/blade-system/dict/dictionary?code=inventory_type'
          },
          {
            label: '储位类型',
            labelWidth: 150,
            prop: 'areaTypeName'
          },
          {
            label: '备注',
            order: 13,
            labelWidth: 150,
            prop: 'remark'
          }
        ]
      };
    },
    /**
     * 打开用户选择模态框
     */
    openUserCommonModal() {
      this.modalName = 'principalModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择负责人员（双击进行选择）',
        url: '/api/blade-system/user/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '用户姓名',
            prop: 'realName',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '所属部门',
            prop: 'deptName',
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '职务',
            prop: 'postName'
          },
          {
            label: '用户平台',
            prop: 'userTypeName'
          }
        ]
      };
    },

    /**
     * 打开供应商选择模态框
     */
    openVendorCommonModal() {
      this.modalName = 'vendorModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择供应商信息（双击进行选择）',
        url: '/api/mes-admin/vendor/page',
        isPage: true,
        rowSelectionType: 'single',
        menu: false,
        editBtn: false,
        menuWidth: 100,
        columnDefs: [
          {
            label: '编码',
            prop: 'code',
            search: true
          },
          {
            label: '名称',
            prop: 'name',
            search: true
          }
        ]
      };
    }
  }
};

export default scraperMixin;
